$(document).ready(function () {
    sskk.onload();
})

var sskk = (function () {

    var init = function () {
        $(window).resize(function () {
            sskk.windowResize()
        });

        $('#select-all').on('click', function () {
            if (this.checked) {
                $('.checkbox_select').each(function () {
                    this.checked = true;
                });
            } else {
                $('.checkbox_select').each(function () {
                    this.checked = false;
                });
            }
        });
    }

    return {
        onload: function () {
            init();
            sskk.windowResize()
            sskk.tableData();
        },
        /*页面大小计算*/
        windowResize: function () {
            var content_xxcj_h = $(document).height() - 20;
            $(".wxn_sskk_body").css("height", content_xxcj_h + "px");
        },
        /*table表格数据车辆*/
        tableData: function () {
            var data = [{
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":1
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":2
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":3
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":4
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                },
                {
                    "carNum": "1",
                    "carCode": "2",
                    "carType": "3",
                    "Suborders": "4",
                    "brandModel": "5",
                    "xZdivisions": "6",
                    "carAddress": "7",
                    "zgTaxsuo": "主管",
                    "filingTime": "8",
                    "engineNum": "10",
                    "invoiceDate": "11",
                    "id":5
                }
            ]
            var table = $('#wxn_sb').DataTable({
                "data": data,
                "columns": [{
                        "data": null,
                        "render": function (data, type, full, meta) {
                            return meta.row + 1 + meta.settings._iDisplayStart;
                        }
                    },
                    {
                        "data": null,
                        'render': function (data, type, full, meta) {
                            console.log(data);
                            return '<input class="checkbox_select" type="checkbox" data-status="' + "" + '"name="id[]" value="' + data.id + '">';
                        }
                    },
                    {
                        "data": "carType"
                    },
                    {
                        "data": "Suborders"
                    },
                    {
                        "data": "brandModel"
                    },
                    {
                        "data": "xZdivisions"
                    },
                    {
                        "data": "carAddress"
                    },
                    {
                        "data": "zgTaxsuo"
                    },
                    {
                        "data": "filingTime"
                    },
                    {
                        "data": "engineNum"
                    },
                    {
                        "data": "invoiceDate"
                    }
                ],
                "scrollY": "240px",
                "scrollX": true,
                "info": false,
                "searching": false,
                "scrollCollapse": true,
                "paging": false,
                // "fixedColumns": {
                //     leftColumns: 2,
                // }
            });

        },

        //批量申报   其余按钮仿照申报按钮写
        onClickSB: function () {
            var selectAtleaseOne = false;
            var selectLoans = [];
            $('.checkbox_select').each(function () {
                if ($(this).is(':checked')) {
                    selectAtleaseOne = true;
                    selectLoans.push($(this).val());
                }
            });

            if (!selectAtleaseOne) {
                alert("请至少选择一条数据");
                return;
            }

            //selectLoans为选中的数据的id
            console.log(selectLoans);
        }
    }
})();